<?php
namespace app\user\controller;
use think\Db;
class Set extends Common{
    protected $uid;
    public function initialize()
    {
        parent::initialize();
        $this->uid=session('user.id');
    }

    public function index(){ 
        $this->assign('title','基本设置');
        return $this->fetch(); 
    }  
    /**
     * 修改密码
     * @param $old_password  旧密码
     * @param $new_password  新密码
     * @param $confirm_password 确认新 密码
     */
    public function repass(){
        $old_password  = input('post.nowpass');
        $new_password = input('post.pass');
        $confirm_password = input('post.repass');
        if(strlen($new_password) < 6)
            return array('code'=>0,'msg'=>'密码不能低于6位字符');
        if($new_password != $confirm_password)
            return array('code'=>0,'msg'=>'两次密码输入不一致');
        //验证原密码
        if(($this->userInfo['password'] != '' && md5($old_password) != $this->userInfo['password']))
            return array('code'=>0,'msg'=>'当前密码不正确');
        if(db('users')->where("id", $this->uid)->update(array('password'=>md5($new_password)))!==false){
            return array('code'=>1,'msg'=>'修改成功');
        }else{
            return array('code'=>0,'msg'=>'修改失败');
        }
    } 
    public function repasspay(){
        $old_password  = input('post.pass_pay');
        $new_password = input('post.repass_pay'); 
        if($old_password != $new_password) return array('code'=>0,'msg'=>'两次密码输入不一致');
        if(db('users')->where("id", $this->uid)->update(array('paypwd'=>md5($new_password)))!==false){
            return array('code'=>1,'msg'=>'修改成功');
        }else{
            return array('code'=>0,'msg'=>'修改失败');
        }
    } 
}